package com.woniu.inlet.subcrible;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MessageListener {

    @RabbitListener(queues = {"topic_queue"})
    public  void message(Message message, Channel channel){

        try {
            String str = new String(message.getBody());
            System.out.println("我已经来到了"+str);
            //邮件
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
        }catch (Exception exception){
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(),true,true);
            } catch (IOException e) {
                e.printStackTrace();
            }
            exception.printStackTrace();
        }
    }

}
